﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Media.Media3D;
using System.Windows;
using System.Timers;

namespace Sinacor.Infra.UI.Controls.SmartClient
{
	public sealed class SinacorMenuControl : DrillDown
	{
		private int _currentLevel = 1;
		private int _maxLevel = 1;
		private SinacorMenuState _state = SinacorMenuState.Floating;
		private SinacorMenuState _dockPosition = SinacorMenuState.DockedLeft;
		private double _xStartPosition = 0;
		private double _yStartPosition = 0;
		private double _rootMenuXScaleFloating;
		private double _rootMenuYScaleFloating;
		private double _rootMenuXScaleDocked;
		private double _rootMenuYScaleDocked;
		private double _windowXSize = System.Windows.SystemParameters.PrimaryScreenWidth;
		private double _windowYSize = System.Windows.SystemParameters.PrimaryScreenHeight;
		private double _dockInterval = 5;
		private static bool _isMoving = false;
		private static bool _isAbleToMove = false;
		private static bool _reassignTitleMenu = false;
		private static bool _isKeyboardNavigating = false;
		private BindingList<SinacorMenuItem> _items;
		private Timer _menuTimer;
		private SinacorMenu rootmenu;

		/// <summary>
		/// Define a posição de dockagem do menu
		/// </summary>
		public SinacorMenuState DockPosition
		{
			get { return _dockPosition; }
			set { _dockPosition = value; }
		}

		/// <summary>
		/// Intervalo esperado para dockar
		/// </summary>
		public double DockInterval
		{
			get { return _dockInterval; }
			set { _dockInterval = value; }
		}

		/// <summary>
		/// Itens do menu
		/// </summary>
		public BindingList<SinacorMenuItem> Items
		{
			get { return _items; }
			set { _items = value; }
		}

		/// <summary>
		/// Seta ou retorna a posição de inicio do eixo X
		/// </summary>
		public double XStartPosition
		{
			get { return _xStartPosition; }
			set { _xStartPosition = value; }
		}

		/// <summary>
		/// Seta ou retorna a posição de inicio do eixo Y
		/// </summary>
		public double YStartPosition
		{
			get { return _yStartPosition; }
			set { _yStartPosition = value; }
		}

		/// <summary>
		/// Seta ou retorna o estado corrente do menu
		/// </summary>
		public SinacorMenuState State
		{
			get { return _state; }
			set
			{
				RemoveElement(this.Children.Count - 2);
				_currentLevel = 1;
				_maxLevel = 1;

				this.SetFadeVisibilityToItem();

				switch (value)
				{
					case SinacorMenuState.DockedLeft:
						this.ResizeToDock();
						this.DockToLeft();
						this.SetRootMenuTemplate("ControlMenuDocked");
						break;
					case SinacorMenuState.DockedRight:
						this.ResizeToDock();
						this.DockToRight();
						this.SetRootMenuTemplate("ControlMenuDockedRight");
						break;
					case SinacorMenuState.Floating:
						this.ResizeToFloat();
						this.UnDock(XStartPosition, YStartPosition);
						this.SetRootMenuTemplate("ControlMenu");
						this.ReStartDockingTimer();
						break;
				}
				_reassignTitleMenu = true;
				_xStartPosition = 0;
				_yStartPosition = 0;
				_isAbleToMove = false;
				_state = value;
				ItemStateHasChanged(_state);
			}
		}

		/// <summary>
		/// Reinicia o timer para dockagem do menu
		/// </summary>
		void ReStartDockingTimer()
		{
			if (_dockInterval > 0)
			{
				if(!this._menuTimer.Enabled)
					this._menuTimer.Enabled = true;

				this._menuTimer.Stop();
				this._menuTimer.Start();
			}
		}

		/// <summary>
		/// Para o timer para dockagem do menu
		/// </summary>
		void StopDockingTimer()
		{
			if (_dockInterval > 0)
			{
				this._menuTimer.Stop();
				this._menuTimer.Enabled = false;
			}
		}

		/// <summary>
		/// Construtor do SinacorMenuControl
		/// </summary>
		public SinacorMenuControl()
		{
			PerspectiveCamera camera = new PerspectiveCamera();
			camera.LookDirection = new Vector3D(0, 0, -1);
			camera.UpDirection = new Vector3D(0, 1, 0);
			camera.Position = new Point3D(0, 0, 1);
			camera.FieldOfView = 90;
			this.Camera = camera;

			ModelVisual3D model = new ModelVisual3D();
			model.Content = new AmbientLight(System.Windows.Media.Colors.White);
			this.Children.Add(model);

			this.PreviewMouseMove += new System.Windows.Input.MouseEventHandler(SinacorMenuControl_PreviewMouseMove);
			this.PreviewMouseUp += new System.Windows.Input.MouseButtonEventHandler(SinacorMenuControl_PreviewMouseUp);
			this.MouseLeave += new System.Windows.Input.MouseEventHandler(SinacorMenuControl_MouseLeave);
			this.MouseEnter += new System.Windows.Input.MouseEventHandler(SinacorMenuControl_MouseEnter);
			this.Loaded += new RoutedEventHandler(SinacorMenuControl_Loaded);

			if (_dockInterval > 0)
			{
				this._menuTimer = new Timer();
				this._menuTimer.Elapsed += new ElapsedEventHandler(CheckTimer);
				this._menuTimer.Interval = _dockInterval * 1000;
				this._menuTimer.AutoReset = true;
			}
		}

		/// <summary>
		/// Navega no menu através do teclado
		/// </summary>
		/// <param name="key">Tecla digitada no teclado</param>
		public void NavigateThruKeyboard(System.Windows.Input.Key key)
		{
			this.SetHitTestVisibleToMenus(false);

			this.StopDockingTimer();

			_isKeyboardNavigating = true;

			SinacorMenu prevMenu = null;
			
			SinacorMenu menu = ((SinacorMenu)((Viewport2DVisual3D)this.Children[this.Children.Count - 1]).Visual);

			if (this.Children.Count > 2)
				prevMenu = ((SinacorMenu)((Viewport2DVisual3D)this.Children[this.Children.Count - 2]).Visual);

			switch(key)
			{
				case System.Windows.Input.Key.Down:
					if (menu.SelectedIndex < (menu.Items.Count - 1))
						menu.SelectedIndex = menu.SelectedIndex + 1;
					break;
				case System.Windows.Input.Key.Up:
					if (menu.SelectedIndex > 0)
						menu.SelectedIndex = menu.SelectedIndex - 1;
					else
						menu.SelectedIndex = 0;
					break;
				case System.Windows.Input.Key.Left:
					if (prevMenu != null)
						this.Keyboard_Navigate_Backward(prevMenu);
					break;
				case System.Windows.Input.Key.Right:
					this.Keyboard_Navigate_Forward(menu);
					break;
				case System.Windows.Input.Key.Enter:
					this.Keyboard_Navigate_Forward(menu);
					break;
				case System.Windows.Input.Key.Tab:
					if (menu.SelectedIndex < (menu.Items.Count - 1))
						menu.SelectedIndex = menu.SelectedIndex + 1;
					else
						menu.SelectedIndex = 0;
					break;
				case System.Windows.Input.Key.Escape:
					this.Keyboard_Navigate_Backward(rootmenu);
					break;
			}

			this.ReStartDockingTimer();
		}

		/// <summary>
		/// Assina o evento que é disparado quando o mouse entra no menu
		/// </summary>
		void SinacorMenuControl_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			this.StopDockingTimer();
		}

		/// <summary>
		/// Assina o evento que é disparado quando o mouse sai de cima do menu
		/// </summary>
		void SinacorMenuControl_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			if (this._currentLevel == 1)
				this.ReStartDockingTimer();
		}

		/// <summary>
		/// Navega no menu abrindo um container filho, ou abrindo uma janela
		/// </summary>
		/// <param name="m">Menu corrente</param>
		void Keyboard_Navigate_Forward(SinacorMenu m)
		{
			if (m.SelectedIndex >= 0 && !_isMoving)
			{
				this.StopDockingTimer();

				SinacorMenuItem selectedItem = (SinacorMenuItem)m.SelectedItem;

				int level = m.Level;
				if (level == _maxLevel)
				{
					if (!DrillDownAnimation.IsAnimating)
					{
						if (selectedItem.Items != null && selectedItem.Items.Count > 0)
						{
							this.CreateElement(selectedItem.Items, selectedItem.SubItemXScale, selectedItem.SubItemYScale, selectedItem.IsScaledByItem, selectedItem.MenuType);
							m.SelectedIndex = -1;
						}
						else
							this.SelectedItemHasChanged(selectedItem);
					}
				}
				this.SetFadeVisibilityToItem();
			}
		}

		/// <summary>
		/// Navega no menu voltando um item
		/// </summary>
		/// <param name="m">Menu para o qual se deve voltar</param>
		void Keyboard_Navigate_Backward(SinacorMenu m)
		{
			if (!_isMoving)
			{
				this.StopDockingTimer();

				SinacorMenuItem selectedItem = (SinacorMenuItem)m.SelectedItem;

				int level = m.Level;

				if (!DrillDownAnimation.IsAnimating)
				{
					this.RemoveElement(_maxLevel - level);
					_maxLevel = level;
					_currentLevel = level;
				}
				m.SelectedIndex = -1;
			}
			this.SetFadeVisibilityToItem();
		}

		/// <summary>
		/// Delega a chamada para o metodo de dockar o menu quando o timer for disparado
		/// </summary>
		delegate void TimerDockMenuDelegate();
		
		/// <summary>
		/// Docka o menu de acordo com o disparo do timer
		/// </summary>
		void TimerDockMenu()
		{
			this.State = this.DockPosition;
		}
		
		/// <summary>
		/// Assina o evento de disparo do timer do menu
		/// </summary>
		void CheckTimer(object source, ElapsedEventArgs e)
		{
			if (_currentLevel == 1)
				this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new TimerDockMenuDelegate(TimerDockMenu));
			
			this.StopDockingTimer();
		}

		/// <summary>
		/// Assina o evento de "Carregado" do menu
		/// </summary>
		void SinacorMenuControl_Loaded(object sender, RoutedEventArgs e)
		{
			this.ReassignTitleMenu();
		}

		/// <summary>
		/// Metodo que assina o evento de UnDock do menu
		/// </summary>
		void ReassignTitleMenu()
		{
			((ListBox)((SinacorMenu)((Viewport2DVisual3D)this.Children[1]).Visual).TitleMenu).PreviewMouseDown += new System.Windows.Input.MouseButtonEventHandler(SinacorMenuTitle_PreviewMouseDown);
		}

		/// <summary>
		/// Assina o evento de MouseDown do menu
		/// </summary>
		void SinacorMenuTitle_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			if (this.State == SinacorMenuState.Floating)
			{
				_isAbleToMove = true;
			}
			else
				this.State = SinacorMenuState.Floating;
		}

		/// <summary>
		/// Assina o evento de MouseMove do menu
		/// </summary>
		void SinacorMenuControl_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
		{
			this.SetHitTestVisibleToMenus(true);
			_isKeyboardNavigating = false;

			if (_reassignTitleMenu)
			{
				this.ReassignTitleMenu();
				_reassignTitleMenu = false;
            }

			if (_isAbleToMove && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed && !DrillDownAnimation.IsAnimating && State == SinacorMenuState.Floating && _currentLevel == 1)
			{
				this.StopDockingTimer();
				_isMoving = true;
				this.MoveElementFollowMouse(_windowXSize, _windowYSize, e.GetPosition(this).X, e.GetPosition(this).Y, out _xStartPosition, out _yStartPosition);
            }
		}

		/// <summary>
		/// Assina o evento de PreviewMouseUp do menu
		/// </summary>
		void SinacorMenuControl_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			this.ReassignTitleMenu();
			if (this.State == SinacorMenuState.Floating)
			{
				_isMoving = false;
				_isAbleToMove = false;
				this.ReStartDockingTimer();
			}
		}

		/// <summary>
		/// Carrega os dados da raiz do menu
		/// </summary>
		/// <param name="items">Itens a serem adicionados à raiz do menu</param>
		public void LoadMenu(BindingList<SinacorMenuItem> items, double xScale, double yScale, double xScaleDock, double yScaleDock)
		{
			_rootMenuXScaleFloating = xScale;
			_rootMenuYScaleFloating = yScale * items.Count;
			_rootMenuXScaleDocked = xScaleDock;
			_rootMenuYScaleDocked = yScaleDock;

			this.Items = items;
			SinacorMenu m = new SinacorMenu(Items, _currentLevel, true, SinacorMenuType.Root);
			this.Children.Add(new SinacorViewport2D(m, Items.Count, XStartPosition, YStartPosition, xScale, yScale, true).ViewPort2D);

			m.PreviewMouseUp += new System.Windows.Input.MouseButtonEventHandler(m_PreviewMouseUp);
			m.SelectionChanged += new SelectionChangedEventHandler(Element_SelectionChanged);

			rootmenu = ((SinacorMenu)((Viewport2DVisual3D)this.Children[1]).Visual);
		}

		/// <summary>
		/// Assina o evento de PreviewMouseUp primeiro item do menu
		/// </summary>
		void m_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			if (_state == SinacorMenuState.Floating)
			{
				if (sender is SinacorMenu)
				{
					SinacorMenu menu = (SinacorMenu)sender;
					if(menu.Level < _currentLevel)
						menu.SelectedIndex = 0;
				}
			}
		}

		/// <summary>
		/// Seta o titulo do menu
		/// </summary>
		/// <param name="title">Titulo desejado para o menu</param>
		public void SetMenuTitle(string title)
		{
			((SinacorMenu)((Viewport2DVisual3D)this.Children[1]).Visual).SelectedCompany = title;
		}

		/// <summary>
		/// Função chamada ao ser disparado o evento "SelectionChanged" do menu
		/// </summary>
		void Element_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (sender is SinacorMenu && !_isKeyboardNavigating)
			{
				SinacorMenu menu = ((SinacorMenu)sender);
				if (menu.SelectedIndex >= 0 && !_isMoving)
				{
					this.StopDockingTimer();

					SinacorMenuItem selectedItem = (SinacorMenuItem)menu.SelectedItem;

					int level = menu.Level;
					if (level == _maxLevel)
					{
						if (!DrillDownAnimation.IsAnimating)
						{
							if (selectedItem.Items != null && selectedItem.Items.Count > 0)
							{
								this.CreateElement(selectedItem.Items, selectedItem.SubItemXScale, selectedItem.SubItemYScale, selectedItem.IsScaledByItem, selectedItem.MenuType);
								menu.SelectedIndex = -1;
							}
							else
							{
								this.SelectedItemHasChanged(selectedItem);
							}
						}
						else
							menu.SelectedIndex = -1;
					}
					else
					{
						if (!DrillDownAnimation.IsAnimating)
						{
							this.RemoveElement(_maxLevel - level);
							_maxLevel = level;
							_currentLevel = level;

							if (_maxLevel == 1)
								this.ReStartDockingTimer();
						}
						menu.SelectedIndex = -1;
					}
					this.SetFadeVisibilityToItem();
				}
			}
		}

        /// <summary>
        /// Limpa a seleção de itens do menu raiz
        /// </summary>
		public void ClearRootSelection()
        {
            ((SinacorMenu)((Viewport2DVisual3D)this.Children[1]).Visual).SelectedIndex = -1;
        }

		/// <summary>
		/// Cria um novo elemento
		/// </summary>
		/// <param name="items">Itens que existirão dentro do elemento</param>
		void CreateElement(BindingList<SinacorMenuItem> items, double subItemXScale, double subItemYScale, bool scaleByItem, SinacorMenuType menuType)
		{
			_currentLevel++;
			SinacorMenu m = new SinacorMenu(items, _currentLevel, false, menuType);

			if (State == SinacorMenuState.Floating)
			{
				if (_currentLevel == 2)
				{
					((TranslateTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[1]).Transform).Children[0]).OffsetX = 0;
					((TranslateTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[1]).Transform).Children[0]).OffsetY = 0;

					_xStartPosition = 0;
					_yStartPosition = 0;
				}
				this.Children.Add(new SinacorViewport2D(m, items.Count, 0, 0, subItemXScale, subItemYScale, scaleByItem).ViewPort2D);
				this.MoveElementsForward();
			}
			else
			{
				int TotalItems = this.Children.Count - 1;
				if (TotalItems == 1)
				{
					if (_state == SinacorMenuState.DockedLeft)
					{
						this.Children.Add(new SinacorViewport2D(m, items.Count, -1000, 0, subItemXScale, subItemYScale, scaleByItem).ViewPort2D);
						ScaleTransform3D scale = ((ScaleTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[this.Children.Count - 1]).Transform).Children[1]);
						((TranslateTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[this.Children.Count - 1]).Transform).Children[0]).OffsetX = (-1 / scale.ScaleX + (1.3));
					}
					else
					{
						this.Children.Add(new SinacorViewport2D(m, items.Count, 1000, 0, subItemXScale, subItemYScale, scaleByItem).ViewPort2D);
						ScaleTransform3D scale = ((ScaleTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[this.Children.Count - 1]).Transform).Children[1]);
						((TranslateTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[this.Children.Count - 1]).Transform).Children[0]).OffsetX = (1 / scale.ScaleX - (1.3));
					}
				}
				else
				{
					if (_state == SinacorMenuState.DockedLeft)
					{
						TranslateTransform3D translate = (TranslateTransform3D)((Transform3DGroup)this.Children[this.Children.Count - 1].Transform).Children[0];
                        this.Children.Add(new SinacorViewport2D(m, items.Count, translate.OffsetX + 2.1, 0, subItemXScale, subItemYScale, scaleByItem).ViewPort2D);
					}
					else if (_state == SinacorMenuState.DockedRight)
					{
						TranslateTransform3D translate = (TranslateTransform3D)((Transform3DGroup)this.Children[this.Children.Count - 1].Transform).Children[0];
						this.Children.Add(new SinacorViewport2D(m, items.Count, translate.OffsetX - 2.1, 0, subItemXScale, subItemYScale, scaleByItem).ViewPort2D);
					}
				}
			}

			_maxLevel++;

			m.PreviewMouseUp += new System.Windows.Input.MouseButtonEventHandler(m_PreviewMouseUp);
			m.SelectionChanged += new SelectionChangedEventHandler(Element_SelectionChanged);

			if (menuType == SinacorMenuType.ZoomControl)
				WarnZoomControlWasCreated();
		}

		/// <summary>
		/// Remove elemento(s)
		/// </summary>
		/// <param name="totalToRemove">Numero total de elementos a serem removidos</param>
		void RemoveElement(int totalToRemove)
		{
			if (this.Children.Count > 1)
			{
				TranslateTransform3D translate = ((TranslateTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[this.Children.Count - 1]).Transform).Children[0]);

				while (totalToRemove > 0)
				{
					Viewport2DVisual3D viewPort = ((Viewport2DVisual3D)this.Children[this.Children.Count - 1]);
					((SinacorMenu)viewPort.Visual).SelectedIndex = -1;
					viewPort.Visual = null;

					this.Children.RemoveAt(this.Children.Count - 1);
					totalToRemove--;
				}

				if (State == SinacorMenuState.Floating)
					MoveElementsBackwards(translate);
			}

			WarnControlWasRemoved();
		}

		/// <summary>
		/// Volta o foco para o menu raiz
		/// </summary>
		public void MoveToFirstElement()
		{
			RemoveElement(this.Children.Count - 2);
			_currentLevel = 1;
			_maxLevel = 1;

			this.SetFadeVisibilityToItem();

			switch (this.State)
			{
				case SinacorMenuState.DockedLeft:
					break;
				case SinacorMenuState.Floating:
					DrillDownAnimation.MoveElementToDesiredStartPosition(this.Children[1] as Viewport2DVisual3D, XStartPosition, YStartPosition, 0);
					break;
			}
			this.ReStartDockingTimer();
		}

		/// <summary>
		/// Função de tratamento de evento disparada quando um elemento for selecionado
		/// </summary>
		void SelectedItemHasChanged(object classe)
		{
			if (SelectedItemChanged != null)
				SelectedItemChanged(new DrillDownEventArgs(classe));
		}
		public delegate void SelectedDelegate(DrillDownEventArgs e);
		public event SelectedDelegate SelectedItemChanged;

		/// <summary>
		/// Função de tratamento de evento disparada quando o estado do menu for alterado
		/// </summary>
		void ItemStateHasChanged(SinacorMenuState state)
		{
			if (ItemStateChanged != null)
				ItemStateChanged(new DockEventArgs(this.State));
		}
		public delegate void DockedDelegate(DockEventArgs e);
		public event DockedDelegate ItemStateChanged;

		/// <summary>
		/// Função de tratamento de evento disparada quando o controle de zoom é aberto
		/// </summary>
		void WarnZoomControlWasCreated()
		{
			if (ZoomControlIsCreated != null)
				ZoomControlIsCreated();
		}
		public delegate void ZoomControlWasCreatedHandler();
		public event ZoomControlWasCreatedHandler ZoomControlIsCreated;

		/// <summary>
		/// Função de tratamento de evento disparada quando um filho do menu foi fechado
		/// </summary>
		void WarnControlWasRemoved()
		{
			if (ControlWasRemoved != null)
				ControlWasRemoved();
		}
		public delegate void ControlWasRemovedHandler();
		public event ControlWasRemovedHandler ControlWasRemoved;

		/// <summary>
		/// Metodo que aplica a escala correta para que o menu seja apresentado como Dockado
		/// </summary>
		void ResizeToDock()
		{
			((ScaleTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[1]).Transform).Children[1]).ScaleX = _rootMenuXScaleDocked;
			((ScaleTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[1]).Transform).Children[1]).ScaleY = _rootMenuYScaleDocked;
		}

		/// <summary>
		/// Metodo que aplica a escala correta para que o menu seja apresentado como Flutuante
		/// </summary>
		void ResizeToFloat()
		{
			((ScaleTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[1]).Transform).Children[1]).ScaleX = _rootMenuXScaleFloating;
			((ScaleTransform3D)((Transform3DGroup)((Viewport2DVisual3D)this.Children[1]).Transform).Children[1]).ScaleY = _rootMenuYScaleFloating;
		}

		/// <summary>
		/// Metodo que aplica o template do menu podendo ser de dockado ou flutuante
		/// </summary>
		/// <param name="templateName">Nome do template que se deseja aplicar</param>
		void SetRootMenuTemplate(string templateName)
		{
			((SinacorMenu)((Viewport2DVisual3D)this.Children[1]).Visual).SetMenuItemTemplate(templateName);
		}

		/// <summary>
		/// Metodo que seleciona o indice do primeiro item do menu
		/// </summary>
		/// <param name="index">Indice o qual se deseja selecionar</param>
		public void SetRootMenuSelectedIndex(int index)
		{
			((SinacorMenu)((Viewport2DVisual3D)this.Children[1]).Visual).SelectedIndex = index;
		}

		/// <summary>
		/// Retornar a instancia do controle de zoom existente em um viewport
		/// </summary>
		/// <returns>A instancia do controle de zoom</returns>
		public object GetSinacorZoom()
		{
			return ((SinacorMenu)((Viewport2DVisual3D)this.Children[this.Children.Count - 1]).Visual).GetSinacorZoom() as SinacorZoom;
		}

		public void SetHitTestVisibleToMenus(bool isHitTestVisible)
		{
			//int Total = this.Children.Count;
			//for (int i = 1; i < Total; i++)
			//{
			//    ((SinacorMenu)((Viewport2DVisual3D)this.Children[i]).Visual).IsHitTestVisible = isHitTestVisible;
			//    //((SinacorMenu)((Viewport2DVisual3D)this.Children[i]).Visual).MoveFocus(new System.Windows.Input.TraversalRequest(System.Windows.Input.FocusNavigationDirection.First));
			//}
		}
	}
}